<?php
header('Content-type: application/json');
$query = $_GET["query"];
$username='c5980S11u17';
$password='4610';
$database='c5980S11u17';

$link = mysql_connect('db.cselabs.umn.edu:3313',$username,$password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database) or die( "Unable to select database");
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}

$query = "SELECT uni_name from uni_wiki_info WHERE uni_name LIKE '%$query%' LIMIT 10";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $output[$i] = $row["uni_name"];
    $i++;
}
echo json_encode($output);

mysql_free_result($result);
?>

